<?php
$this->breadcrumbs=array(
	'Supplies'=>array('index'),
	'Manage',
);

$this->menu=array(
	array('label'=>'List Supplies', 'url'=>array('index')),
	array('label'=>'Create Supplies', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('supplies-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<div id="tnm-body">
    	<div class="tnm-col-left">
        	<h2 class="title-tnm-col-left">Quản lí vật tư</h2>
            <div class="sort">
                <div class="button">
                <a href="<?php echo $this->createUrl('/supplies/create') ?>">Thêm vật tư</a>
                </div>
                <div class="button" style="margin-left: 5px;">
                <a href="<?php echo $this->createUrl('/import') ?>">Quản lí nhập hàng</a>
                </div>
            </div>
            <div class="content-tnm-col-left">
                     <?php $this->widget('zii.widgets.grid.CGridView', array(
                    	'id'=>'supplies-grid',
                    	'dataProvider'=>$model->search(),
                    	'filter'=>$model,
                    	'columns'=>array(
                    		//'id',
                    		'type',
                    		'name',
                    		'number',
                    		'unit',
                    		array(
                            	'class'=>'CButtonColumn',
                                'template' => '{update}{delete}',
                            ),
                    	),
                    )); ?>        	
            </div>
            <div class="bottom-tnm-col-left"></div>
        </div>
        <div class="tnm-col-right">
        	<h2 class="title-tnm-col-right">Nhập vật tư</h2>
            <div class="content-tnm-col-right">
            	<div id="sub-col-right">
                	<div class="dialog-new">
                    <?php $form=$this->beginWidget('CActiveForm', array(
                        	'id'=>'add-supplies-form',
                        	'enableAjaxValidation'=>false,
                        )); ?>                        
                        <div class="style-form">
                            <dl>
                                <dt>Tên hàng hóa:</dt>
                                <dd>
                                    <?php echo CHtml::dropDownList('Supplies[id]','Supplies[id]',CHtml::listData(Supplies::model()->findAll(),'id','name')); ?>
                                </dd>
                            </dl>
                            <dl>
                                <dt>Hoặc hàng hóa khác:</dt>
                                <dd>
                                    <input type="text" name="Supplies[other]" />
                                </dd>
                            </dl>
                            <dl>
                                <dt>
                                    Số lượng
                                </dt>
                                <dd>
                                    <input type="text" name="Supplies[number]"/>
                                </dd>
                            </dl>      
                            <dl>
                                <dt>
                                    Tổng tiền (VNĐ)
                                </dt>
                                <dd>
                                    <input type="text" name="Supplies[price]"/>
                                </dd>
                            </dl>                      
                            <dl>
                                <dt></dt>
                                <dd>
                                    <div class="button" style="padding-top:20px; margin-left:80px; clear:both"><a href="#" id="add_supplies">Thêm</a></div>                					
                                </dd>                  
                            </dl>
                        </div>
                    <?php $this->endWidget(); ?>
                </div>
                	
                </div>
            </div>
            <div class="bottom-tnm-col-right"></div>
        </div>
    </div>
<script type="text/javascript">
    $().ready(function(){
        $('#add_supplies').click(function(){
           var url = '<?php echo $this->createUrl('/supplies/ajaxCreate') ?>';
           $.post(url,$('#add-supplies-form').serialize(),function(resp){
                alert(resp);
                if(resp == 'Lưu mặt hàng thành công !')
                {
                    $('#add-supplies-form').find('input').val('');
                }
           });
           return false; 
        });
    });
</script>